<?
if(isset($_POST['type'])){
    include('../libraries/data.lib.php');
    if($_POST['type']=="config"&&isset($_POST['url'])&&data::url_exists($_POST['url'])){
        include('../../config.php');
        
        $url=$_POST['url'];
        
        mysql_connect($host, $user, $pass) or die ("Error");
        mysql_query('SET NAMES utf8');
        mysql_selectdb($db) or die ("Error2");
        
        if(file_exists('../../db.sql')){
            $f=fopen('../../db.sql', 'r');
            $contents = '';
            while (!feof($f)) {
              $contents .= fread($f, 8192);
            }
            fclose($f);
            
            while($x=strpos($contents, ';')){
                $query=substr($contents, 0, $x);
                $contents=substr($contents, $x+1);
                mysql_query($query);
            }
            
            mysql_query("UPDATE `config` SET `value` = '".$url."' WHERE `name`='url'");
            
            $pos=strpos($url, '/', 7);
            $len=strlen($path);
            $path=substr($url, $pos);
            
            mysql_query("UPDATE `config` SET `value` = '".$path."' WHERE `name`='path'");
            
            print('{"saved":true}');
        }
        else{
            print('{"saved":false}');
        }
    }
}
?>